/**
 * 删除给定值的叶子节点
 * https://leetcode.cn/problems/delete-leaves-with-a-given-value/
 * 后序遍历
 * 在返回的时候判断，如果当前的节点的值等于target 并且当前的节点是叶子节点就返回null
 */
class Solution4 {
    public TreeNode removeLeafNodes(TreeNode root, int target) {
        if(root == null) {
            return null;
        }
        root.left = removeLeafNodes(root.left,target);
        root.right = removeLeafNodes(root.right,target);
        if(root.val == target && root.left == null && root.right == null) {
            return null;
        }
        return root;
    }
}